using System;
using System.Web.Mvc;
using Roommate.Infrastructure.Persistence;
using Roommate.Services;
using Roommate.Services.Messages;
using Roommate.Web.Models;
using Roommate.Web.Models.Administration;
using MvcContrib;

namespace Roommate.Web.Controllers
{
    public class AdministrationController:Controller
    {
        private IAdministrationService administrationService;

        public AdministrationController(IAdministrationService administrationService)
        {
            this.administrationService = administrationService;
        }

        public ActionResult ResetDatabase()
        {
            new DatabaseAdministration().ResetDatabase();

            return View();
        }
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult CreateRoom()
        {
            return View(new CreateRoomViewModel());
        }


        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CreateRoom(CreateRoomRequest formData)
        {
            administrationService.CreateRoom(formData);

            return this.RedirectToAction(c => c.DisplayRoom(formData.RoomNumber));
        }

        public ActionResult DisplayRoom(string roomNumber)
        {
            return View(new DisplayRoomViewModel{Room = new Room{Number = roomNumber}});
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult SetSystemTime()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult SetSystemTime(DateTime timeToSet)
        {
            SystemTime.Now = () => timeToSet;

            return View();
        }

        
    }
}